package com.youxin.cpcenter.controller;

import java.util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.youxin.busfoundation.bean.ent.RequestCompanyCorrectionBean;
import com.youxin.busfoundation.bean.ent.RequestCompanyInfoBean;
import com.youxin.busfoundation.common.es.bean.*;
import com.youxin.busfoundation.utils.es.EsBasePage;
import com.youxin.cpcenter.common.log.LogMethod;
import com.youxin.cpcenter.service.CompanyCorrectionInfoService;
import com.youxin.cpcenter.service.CompanyInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.youxin.busfoundation.bean.ResponseObject;
import com.youxin.busfoundation.bean.ent.RequestEntInfo;
import com.youxin.cpcenter.service.SearchService;
import com.youxin.foundation.utils.ObjectUtils;

@RestController
public class CompanyInfoController extends BaseController{

	@Autowired
	private SearchService searchService;

	@Autowired
	private CompanyInfoService companyInfoService;

	@Autowired
	private CompanyCorrectionInfoService companyCorrectionInfoService;

	@LogMethod(id="ent.api.enterprise",eventContent={})
	@RequestMapping(value = "/api/enterprise", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseObject queryCompanyInfo(HttpServletRequest request, HttpServletResponse httpServletResponse,
			@RequestBody RequestEntInfo reqeustBean)  {
		try {			
			Objects.requireNonNull(reqeustBean, "参数不能为空");
			Objects.requireNonNull(reqeustBean.getUid(), "企业标识不能为空");
			CompanyInfoBean result=searchService.searchCompany(reqeustBean);
			return new ResponseObject(result);
		} catch (Exception e) {
			logger.error("/queryCompanyInfo异常", e);
			return ResponseObject.systemError(e);
		}
	}

	

	/**
	 * @Title: company_correction
	 * @Description: 企业纠错接口
	 * @param @param request
	 * @param @param response
	 * @param @param response
	 * @param @throws reqeustBean
	 * @return void
	 * @throws
	 */
	@LogMethod(id="ent.api.company.correction",eventContent={})
	@RequestMapping(value="/api/company/correction",method=RequestMethod.POST)
	public ResponseObject companyCorrection(HttpServletRequest request, HttpServletResponse response ,
							  @RequestBody RequestCompanyCorrectionBean reqeustBean) throws Exception {
		try {
			ObjectUtils.requestNonEmpty(reqeustBean.getMemberUid(), "会员UID不能为空");
			ObjectUtils.requestNonEmpty(reqeustBean.getCompanyUid(), "企业UID不能为空");
			ObjectUtils.requestNonEmpty(reqeustBean.getInfo(), "纠错信息不能为空");
			return companyCorrectionInfoService.companyCorrection(reqeustBean);
		} catch (Exception e) {
			logger.error("/api/company/correction异常", e);
		    return ResponseObject.systemError(e);
		}
	}

	/**
	 * @desc  企业画像-基本详情
	 * @param request
	 * @param httpServletResponse
	 * @param requestBean
	 * @return
	 */
	@LogMethod(id="ent.api.company.info",eventContent={})
	@RequestMapping(value = "/api/company/info", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseObject queryCompanyInfo(HttpServletRequest request, HttpServletResponse httpServletResponse,
												@RequestBody RequestCompanyInfoBean requestBean)  {
		try {
			ObjectUtils.requestNonNull(requestBean, "参数不能为空");
			ObjectUtils.requestNonEmpty(requestBean.getUid(), "企业标识不能为空");
			return companyInfoService.companyInfo(requestBean);
		} catch (Exception e) {
			logger.error("/queryCompanyInfo", e);
			return ResponseObject.systemError(e);
		}
	}

	/**
	 * @desc  企业画像-商务合作
	 * @param request
	 * @param httpServletResponse
	 * @param reqeustBean
	 * @return
	 */
	@LogMethod(id="ent.api.company.cooperate",eventContent={})
	@RequestMapping(value = "/api/company/cooperate", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseObject queryCompanyCooperate(HttpServletRequest request, HttpServletResponse httpServletResponse,
												@RequestBody RequestCooperateBean reqeustBean)  {
		try {
			ObjectUtils.requestNonNull(reqeustBean, "参数不能为空");
			ObjectUtils.requestNonEmpty(reqeustBean.getCompanyUid(), "企业标识不能为空");
			return companyInfoService.searchCooperate(reqeustBean);
		} catch (Exception e) {
			logger.error("/queryCompanyCooperate", e);
			return ResponseObject.systemError(e);
		}
	}

	/**
	 * @desc  企业画像-企业实力
	 * @param request
	 * @param httpServletResponse
	 * @param reqeustBean
	 * @return
	 */
	@LogMethod(id="ent.api.company.strength",eventContent={})
	@RequestMapping(value = "/api/company/strength", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseObject queryCompanyStrength(HttpServletRequest request, HttpServletResponse httpServletResponse,
											   @RequestBody RequestStrengthBean reqeustBean)  {
		try {
			ObjectUtils.requestNonNull(reqeustBean, "参数不能为空");
			ObjectUtils.requestNonEmpty(reqeustBean.getCompanyUid(), "企业标识不能为空");
			return companyInfoService.companyStrength(reqeustBean);
		} catch (Exception e) {
			logger.error("/queryCompanyStrength", e);
			return ResponseObject.systemError(e);
		}
	}

	/**
	 * @desc  企业画像-风险预警
	 * @param request
	 * @param httpServletResponse
	 * @param reqeustBean
	 * @return
	 */
	@LogMethod(id="ent.api.company.riskwarn",eventContent={})
	@RequestMapping(value = "/api/company/riskwarn", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseObject queryCompanyRiskwarn(HttpServletRequest request, HttpServletResponse httpServletResponse,
											   @RequestBody RequestRiskwarnBean reqeustBean)  {
		try {
			ObjectUtils.requestNonNull(reqeustBean, "参数不能为空");
			ObjectUtils.requestNonEmpty(reqeustBean.getCompanyUid(), "企业标识不能为空");
			return companyInfoService.companyRiskwarn(reqeustBean);
		} catch (Exception e) {
			logger.error("/api/company/correction异常", e);
			return ResponseObject.systemError(e);
		}
	}

	/**
	 * @desc  我的企业信息
	 * @param request
	 * @param httpServletResponse
	 * @return
	 */
	@LogMethod(id="ent.api.company.me",eventContent={})
	@RequestMapping(value = "/api/company/me", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseObject queryCompanyMe(HttpServletRequest request, HttpServletResponse httpServletResponse)  {
		try {
			return companyInfoService.companyMe();
		} catch (Exception e) {
			logger.error("/queryCompanyMe", e);
			return ResponseObject.systemError(e);
		}
	}
	
}
